import requests
from bs4 import BeautifulSoup

url = "https://so.gushiwen.cn/shiwenv_45c396367f59.aspx"
req = requests.get(url)
if req.status_code == 200:
    soup = BeautifulSoup(req.text, 'html.parser')
    title = soup.h1.get_text()
    author = soup.find('p', 'source').get_text()
    poems = soup.find(id="contson45c396367f59").get_text("|").strip().split("|")
    with open(f'{title}.txt', 'w', encoding='utf-8') as file:
        file.write(title+'\n')
        file.write(author + "\n")
        for i in poems:
            file.write(i+ "\n")